from manimlib import *
import sys

sys.path.append("../..")
from customized import *
from numpy import flip, insert

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'


class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        radius = 5
        ellipse = Ellipse().set_width(10).shift(DOWN * 2).stretch(0.7,1).set_color(BLACK)
        o = ellipse.get_center()
        arc6 = CustomizedArc(0, PI, radius=radius,arc_center=o)
        # cube
        high = 4
        xxx = np.sqrt(radius ** 2 - high ** 2)
        a, b, c, d = o + LEFT * xxx + UP * high, [-0.1, 2.8, 0], o + RIGHT * xxx + UP * high, [0.1, 1, 0]
        a_, c_, d_ = a + DOWN * high, c + DOWN * high, d + DOWN * high
        aa_, cc_, dd_, a_d_, c_d_ = CustomizedLine(a, a_), CustomizedLine(c, c_), CustomizedLine(d, d_), CustomizedLine(a_, d_), CustomizedLine(c_, d_)
        o = (a + c) / 2
        oc_ = CustomizedLine(o, c_).set_color(LV)
        abcd = CustomizedPolygon(a, b, c, d)
        self.add(oc_, ellipse, arc6, abcd, aa_, cc_, dd_, a_d_, c_d_,
                 DashedLine(a, c).set_color(BLACK),
                 DashedLine(b, d).set_color(BLACK),

                 )
        self.wait()


class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        radius = 5
        ellipse = Ellipse().set_width(10).shift(DOWN * 2).stretch(0.7,1).set_color(BLACK)
        o = ellipse.get_center()
        arc6 = CustomizedArc(0, PI, radius=radius,arc_center=o)
        # cube
        high = 4
        xxx = np.sqrt(radius ** 2 - high ** 2)
        a, b, c, d = o + LEFT * xxx + UP * high, [-0.2, 2.8, 0], o + RIGHT * xxx + UP * high, [0.2, 1, 0]
        a_, c_, d_ = a + DOWN * high, c + DOWN * high, d + DOWN * high
        aa_, cc_, dd_, a_d_, c_d_ = CustomizedLine(a, a_), CustomizedLine(c, c_), CustomizedLine(d, d_), CustomizedLine(a_, d_), CustomizedLine(c_, d_)
        o = (a + c) / 2
        oc_ = CustomizedLine(o, c_).set_color(LV)
        abcd = CustomizedPolygon(a, b, c, d)
        self.add(oc_, ellipse, arc6, abcd, aa_, cc_, dd_, a_d_, c_d_,
                 DashedLine(a, c).set_color(BLACK),
                 DashedLine(b, d).set_color(BLACK),
                 )
        # p2
        o_ = o + DOWN * high
        co_ = CustomizedLine(c, o_).set_color(JH)
        self.add(co_,
                 DashedLine(a_, c_).set_color(BLACK),
                 DashedLine(o, o_).set_color(BLACK),
                 dd_
                 )
        self.wait()


class p3(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        s_red = CustomizedSquare(4).stretch(2, 1).set_fill(RED, 1).set_stroke(WHITE)
        s1 = s_red.copy().shift(LEFT * 6)
        s2 = s_red.copy().shift(RIGHT * 6)
        self.add(s1, s2)
        #
        radius = 6
        arc = CustomizedArc(0, PI / 2,radius=radius).shift(DL * 3)
        d = [-3, -3, 0]
        self.add(arc, CustomizedLine(d, d + UP * radius), CustomizedLine(d, d + RIGHT * radius))
        c = [0, -3, 0]
        b = c + UP * 3 * np.sqrt(3)
        a = b + LEFT * 3
        self.add(CustomizedPolygon(a, b, c), CustomizedLine(a, c).set_color(LV),
                 CustomizedTex('A').next_to(a, LEFT),
                 CustomizedTex('B').next_to(b, UR),
                 CustomizedTex('C').next_to(c, DOWN),
                 CustomizedTex('D').next_to(d, DOWN),
                 CustomizedTex('5').move_to([-1.5, -3.3, 0]),
                 CustomizedTex('5').move_to([1.5, -3.3, 0]),
                 )
        self.wait()


class p4(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        s_red = CustomizedSquare(4).stretch(2, 1).set_fill(RED, 1).set_stroke(WHITE)
        s1 = s_red.copy().shift(LEFT * 6)
        s2 = s_red.copy().shift(RIGHT * 6)
        self.add(s1, s2)
        #
        radius = 6
        arc = CustomizedArc(0, PI / 2,radius=radius).shift(DL * 3)
        d = [-3, -3, 0]
        self.add(arc, CustomizedLine(d, d + UP * radius), CustomizedLine(d, d + RIGHT * radius))
        c = [0, -3, 0]
        b = c + UP * 3 * np.sqrt(3)
        a = b + LEFT * 3
        self.add(CustomizedPolygon(a, b, c), CustomizedLine(a, c).set_color(LV), CustomizedLine(b, d).set_color(JH),
                 CustomizedTex('A').next_to(a, LEFT),
                 CustomizedTex('B').next_to(b, UR),
                 CustomizedTex('C').next_to(c, DOWN),
                 CustomizedTex('D').next_to(d, DOWN),
                 CustomizedTex('5').move_to([-1.5, -3.3, 0]),
                 CustomizedTex('5').move_to([1.5, -3.3, 0]),
                 )
        self.wait()